#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  04-filename_standard.sh
# Version	:  2.0
# Date		:  2024/04/26
# Author	:  yaoxiyao
# Email		:  yaoxiyao@kylinsec.com.cn
# Function	:  文件命名规范测试
# Out		:
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="文件命名规范测试"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB() {
    return $TPASS
}

## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB() {
    return $TPASS
}

## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB() {
    testcase_1
    return $TPASS
}

## TODO : 文件命名规范测试
testcase_1() {
    which ks-showinfo
    if [ "$?" -ne 0 ]; then
        local osrelease_file="/etc/os-release"
        local kylinrelese="/etc/kylinsec-release"
        local release_standard="NAME=\"KylinSec OS\"\nVERSION=\"3 (Qomolangma)\"\nID=\"kylinsecos\"\nID_LIKE=\"openeuler\"\nVERSION_ID=\"3\"\nPRETTY_NAME=\"KylinSec OS Linux 3 (Qomolangma)\"\nANSI_COLOR=\"0;31\"\nHOME_URL=\"https://www.kylinsec.com.cn\"\nBUG_REPORT_URL=\"https://support.kylinsec.com.cn\"\n"
        local release_standard_content=$(echo -e ${release_standard})
        local osrelease_content=$(cat "${osrelease_file}")
        if [[ "${osrelease_content}" == "${release_standard_content}" ]]; then
            OutputRet_LTFLIB ${TPASS}
            TestRetParse_LTFLIB "${osrelease_file}内容合规"
        else
            Info_LLE "请检查下面内容，not kylinos,is kylinsec"
            cat "${osrelease_file}"
            OutputRet_LTFLIB ${TFAIL}
            TestRetParse_LTFLIB "${osrelease_file}内容不合规"
        fi
        cat "${kylinrelese}" | grep "KylinSec OS release 3 (Qomolangma)" &>/dev/null
        CommRetParse_LTFLIB "cat ${kylinrelese}|grep KylinSec OS release 3 (Qomolangma)"
    else
        Info_LLE "V6版本暂无此用例适配"
    fi
}

#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
